<template>
	<view class="classlist">
		<view class="top">
			<view class="search">
				<image src="@/static/index/ss.png" mode=""></image>
				<input type="text" placeholder="搜索商品" placeholder-style="color:#B8B9BD" disabled
					@click="toPage('/pages/index/goods-search')" />
			</view>
		</view>
		<view class="left">
			<view class="left_ul">
				<view @click="navClick(item)" class="left_li" v-for="(item,index) in navlist" :key="index">
					<image :src="item.img_url | getImg" mode=""></image>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCategory,
		GoodsList
	} from "@/api/api.js"
	export default {
		data() {
			return {
				navlist: [],
				goodslist: [],
				last_page: 1,
				page: 1,
				category_id: '',
				category: []
			}
		},
		onLoad() {
			// this.getCategory()
			this.GoodsList()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.GoodsList()
			}
		},
		methods: {
			getCategory() {
				getCategory().then(res => {
					if (res.status == 1) {
						this.navlist = res.data
						this.category = this.navlist[0]
						this.GoodsList()
					}
				})
			},
			GoodsList() {
				GoodsList({
					type: this.category.id || '',
					page: this.page
				}).then(res => {
					if (res.status == 1) {
						this.navlist = res.data.class
						if (this.category == '') {
							this.category = this.navlist[0]
						}
						this.goodslist = this.goodslist.concat(res.data.goods.data)
						this.last_page = res.data.goods.last_page
					}
				})
			},
			navClick(item, index) {
				uni.navigateTo({
					url: './goods?id=' + item.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.top {
		background: #fff;
		padding: 10px 0;
		position: sticky;
		top: 0px;
		/* #ifdef H5 */
		top: 44px;
		/* #endif */
		z-index: 99;

		.news {
			text-align: right;
			padding-right: 5%;
			position: fixed;
			top: 8px;
			z-index: 99999;
			right: 2%;

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.logo {
			display: flex;
			justify-content: center;
			padding-bottom: 30rpx;
			padding-top: 20rpx;

			image {
				width: 60%;
				height: 90px;
			}
		}

		.search {
			position: relative;
			width: 96%;
			background: #F5F5F5;
			border-radius: 20px;
			margin: 0px auto;
			display: flex;
			align-items: center;
			padding: 0 10px;
			box-sizing: border-box;
			padding-left: 20px;

			image {
				width: 20px;
				height: 20px;
			}

			input {
				width: 80%;
				margin-left: 10px;
				line-height: 35px;
				height: 35px;
				color: #000;
				font-size: 15px;
			}


		}

	}

	.left_ul {
		display: flex;
		flex-wrap: wrap;
		margin-top: 10px;
	}

	.left_li {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 25%;
		margin: 5px 0;

		image {
			width: 80px;
			height: 80px;
			margin-bottom: 5px;
			border-radius: 8px;
		}

		text {
			font-size: 14px;
			color: #666;
		}
	}
</style>